const { tags } = require("./mock");

module.exports = (app) => {
  app.get("/api/tags", (req, res) => {
    const { value = "", desc = "默认"  } = req.query;

		const result = [...tags].sort((a, b) => {
			if(desc === '默认') return
			if(desc === '首字母') return a.title[0].charCodeAt() - b.title[0].charCodeAt()
			if(desc === '最新') return new Date(b.createTime) - new Date(a.createTime)
		})

    res.send({
      code: 200,
      data: result.filter(
        (v) => v.title.includes(value) || v.desc.includes(value)
      ),
    });
  });
};
